package com.czz.manage.controller.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czz.common.exception.ResultCodeEnum;
import com.czz.common.vo.R;
import com.czz.manage.entity.CourseConsult;
import com.czz.manage.entity.Order;
import com.czz.manage.query.ConsultQuery;
import com.czz.manage.service.CourseConsultService;
import com.czz.manage.vo.ConsultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ConsultTeacherController
 * @Author Czz
 * @Date 2020/2/19
 * @Time 13:17
 **/
@RestController
@RequestMapping(value = "/teacher/consults")
public class ConsultTeacherController {

    @Autowired
    CourseConsultService consultService;

    /**
    * @Description 分页查询课程咨询
    * @Param [page, limit, consultQuery]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/19
    * @Time 13:32
    **/
    @GetMapping(value = "{page}/{limit}/{id}")
    public R getConsultPageList(@PathVariable Long page, @PathVariable Long limit,@PathVariable String id, ConsultQuery consultQuery){
        if (page <= 0 || limit <= 0 || StringUtils.isEmpty(id)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        Page<ConsultVo> pageParam = new Page<>(page, limit);
        List<ConsultVo> records = consultService.getConsultPageList(pageParam,id,consultQuery);
        pageParam.setRecords(records);
        Long total = pageParam.getTotal();
        return R.ok().data("total", total).data("rows", pageParam.getRecords());
    }

    /**
    * @Description 根据id查询课程咨询
    * @Param [id]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/19
    * @Time 16:02
    **/
    @GetMapping(value = "{id}")
    public R getConsultById(@PathVariable String id){
        if (StringUtils.isEmpty(id)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        CourseConsult consult = consultService.getById(id);
        return R.ok().data("item",consult);
    }

    /**
    * @Description 根据id回复课程咨询
    * @Param [id, consultVo]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/19
    * @Time 16:04
    **/
    @PutMapping(value = "")
    public R updateConsultById(ConsultVo consultVo){
        if (StringUtils.isEmpty(consultVo.getConsultId()) || StringUtils.isEmpty(consultVo.getConsult())){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        consultService.updateConsultById(consultVo);
        return R.ok();
    }
}
